// pages/person/person.js
const userApi = require('../../config').userApi;
Page({
    /**
     * 页面的初始数据
     */
    data: {
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        list_1: [
            {
                name: '我的通知',
                page: 'notify'
            }, {
                name: '考勤记录',
                page: 'sign'
            }, {
                name: '绩效考核',
                page: 'appraisal'
            }, {
                name: '我的动态',
                page: 'myspace'
            }
        ],
        list_2: [{
            id: 'setup',
            name: '设置',
            page: 'setup'
        }],
        userImage: '/images/test_head.png',
        user: {
            name: "胡兴",
            mobile: "13619560448"
        }
    },
    changeImage: function () {
        console.log("ssssssssssssss");
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let loginFlag = wx.getStorageSync("loginFlag");
        console.log(loginFlag);
        let that = this;
        if (loginFlag) {
            wx.request({
                url: userApi,
                header: {
                    loginFlag: loginFlag
                },
                success: function (res) {
                    console.log(res.data)
                    let data = res.data
                    if (data.code == 0) {
                        wx.setStorageSync('userid', data.data.userId)
                        that.setData({
                            user: {
                                name: data.data.name,
                                mobile: data.data.email
                            }
                        })

                    } else if (data.code == 1) {
                    } else if (data.code == 1) {
                    }
                },
                fail: function (res) {
                    const hasUser = wx.setStorageSync(hasUser, false)
                },
                complete: function (res) { },
            })
        } else {
            wx.login({
                success: function (res) { },
                fail: function (res) { },
                complete: function (res) { },
            })
        }
        var name = this.data.user.name,
            mobile = this.data.user.mobile;
        console.log(name);
        console.log(mobile);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {


    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        const userid = wx.getStorageSync("userid")
        console.log('userid' + userid);
        if (!userid) {
            wx.showModal({
                title: '提示',
                content: '当前微信未绑定账号,是否现在绑定',
                success: function (res) {
                    if (res.confirm) {
                        console.log('绑定')
                        wx.navigateTo({
                            url: '/pages/setuser/login'
                        })
                    } else if (res.cancel) {
                        console.log('退出')
                        // wx.navigateBack({
                        //     delta: 1
                        // })  
                    }
                }
            })
        }

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})